package com.jiangyg.mall.admin.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jiangyg.mall.admin.entity.DepartUser;
import com.jiangyg.mall.admin.entity.User;
import com.jiangyg.mall.db.mybatis.metadata.Pager;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 类描述：部门和用户关联关系
 *
 * @author jiangyg
 * @date 2021-10-17
 */
@Mapper
public interface DepartUserDao extends BaseMapper<DepartUser> {

    /**
     * 功能描述：查询部门下的用户列表
     *
     * @param departId 部门ID
     * @return 用户列表
     */
    @Select("select id, username, fullname, status, mail, phone " +
            "from t_sys_user " +
            "where id in (select user_id from t_sys_depart_user where depart_id = #{departId}  and enable = 'Y') and enable = 'Y'")
    List<User> selectUserByDepartId(Pager<User> pager, @Param("departId") Long departId);

    @Select("select id, username, fullname, status, mail, phone " +
            "from t_sys_user " +
            "where id not in (select user_id from t_sys_depart_user where enable = 'Y') and enable = 'Y'")
    List<User> selectUnallocatedUserList();

}
